#include<bits/stdc++.h>
using namespace std;

int mot[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int dig(int n)
{
	int sum=0;
	while(n)
	{
		sum+=n%10;
		n/=10;
	}
	return sum;
}

int jud(int year,int mot,int day,int num)
{
	int sum=dig(year)+dig(mot)+dig(day);
	if(sum==num)
	{
		return 1;
	}
	return 0;
	
}


int main()
{
int n;
cin>>n;
	
	
	for(int sz=0;sz<n;sz++)
	{
		int st,ed,num;
		cin>>st>>ed>>num;

			int cnt=0;
		for(int i=st;i<=ed;i++)
		{
		
			for(int j=1;j<=12;j++)
			{
				if(j==2)
				{
					if((i%4==0&&i%100==0)||(i%400==0))
					{
						for(int day=1;day<=28;day++)
						{
							cnt+=jud(i,j,day,num);
						}
					}
					else
					{
											for(int day=1;day<=29;day++)
																{
																	cnt+=jud(i,j,day,num);
																}
					}
				}
				for(int day=1;day<=mot[j];day++)
					{
					cnt+=jud(i,j,day,num);
					 }
									
				}
			
		}
			cout<<cnt<<"\n";		
		}
	}
	
